using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SimianReshaper;

namespace SimianReshaperUI
{
	public partial class SettingsDialog : Form
	{
		#region fields
		Preferences preferences;
		#endregion

		#region Properties
		public Preferences Preferences
		{
			get { return preferences; }
			set { preferences = value; }
		}
		#endregion

		#region Constructors
		public SettingsDialog(Preferences preferences)
		{
			InitializeComponent();
			this.preferences = preferences.Clone();
			UpdateUI();
		}
		#endregion

		#region UI event handlers
		private void btnOK_Click(object sender, EventArgs e)
		{
			UpdateObject();
			this.DialogResult = DialogResult.OK;
		}
		#endregion

		#region Private methods
		private void UpdateObject()
		{
			if (ValidInputs())
			{
				this.preferences.IgnoreDesignerErrors = this.chkIgnoreDesigner.Checked;
				this.preferences.IgnoreIgnoreList = this.chkIgnoreSuppresses.Checked;
				this.preferences.Threshold = int.Parse(this.txtThreshold.Text);
			}
		}

		private void UpdateUI()
		{
			this.chkIgnoreDesigner.Checked = this.preferences.IgnoreDesignerErrors;
			this.chkIgnoreSuppresses.Checked = this.preferences.IgnoreIgnoreList;
			this.txtThreshold.Text = this.preferences.Threshold.ToString();
		}

		private bool ValidInputs()
		{
			if (!string.IsNullOrEmpty(this.txtThreshold.Text))
			{
				int value = 0;
				if (int.TryParse(this.txtThreshold.Text, out value))
				{
					return true;
				}
			}
			return false;
		}

		#endregion
	}
}